/*
 * EnrollPayFailedFragment.java
 * business
 *
 * Created by chentao on 2017/4/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.discovery.enrollpayfailed;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.base.SuperBaseFragment;
import com.yidiandao.business.ui.orderabout.activeorder.detail.ActiveOrderDetailActivity;
import com.yidiandao.business.ui.url.UrlActivity;
import com.yidiandao.business.utils.UIUtils;

/**
 * View
 */
public class EnrollPayFailedFragment extends SuperBaseFragment
        implements EnrollPayFailedContract.View {

    private EnrollPayFailedContract.Presenter mPresenter;

    private Toolbar mToolbar;

    private TextView mTvPayAgain;

    private TextView mTvShowOrder;

    private TextView mTvPayError;

    public static EnrollPayFailedFragment getInstance() {
        EnrollPayFailedFragment fragment = new EnrollPayFailedFragment();
        return fragment;
    }


    @Override
    public void setPresenter(EnrollPayFailedContract.Presenter presenter) {
        mPresenter = presenter;
    }


    @Override
    public String getPagerTag() {
        return EnrollPayFailedFragment.class.getSimpleName();
    }


    @Override
    public void showToast(String text) {
        UIUtils.showToast(text);
    }


    @Override
    protected void initViews() {
        mToolbar = (Toolbar) mRootView.findViewById(R.id.toolbar);
        mTvPayAgain = (TextView) mRootView.findViewById(R.id.tv_pay_again);
        mTvShowOrder = (TextView) mRootView.findViewById(R.id.tv_show_order);
        mTvPayError = (TextView) mRootView.findViewById(R.id.tv_pay_error);

        initListeners();
    }


    private void initListeners() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivity.finish();
            }
        });

        mTvPayAgain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toPayAgainActivity();
            }
        });

        mTvShowOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toEnrollOrderDetailActivity();
            }
        });
    }


    @Override
    public void toPayAgainActivity() {
        mActivity.finish();
        UrlActivity.actionStartForEnrollOnlinePay(mActivity, mPresenter.getUrl(), null);
    }


    @Override
    public void toEnrollOrderDetailActivity() {
        mActivity.finish();
        ActiveOrderDetailActivity.actionStart(mActivity, mPresenter.getRecId());
    }


    @Override
    public void refreshMessage(String message) {
        mTvPayError.setText(message);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_enroll_pay_failed;
    }


    @Override
    public void refreshContent(int result) {
        superRefreshLayoutState(result);
    }


    @Override
    public int checkResultObject(Object resultObject) {
        return superCheckListState(resultObject);
    }


    @Override
    protected void startLoadData() {
        mPresenter.start();
    }
}
